import { Entity, Column, Index, ManyToOne, JoinColumn } from 'typeorm';
import { BaseEntity } from '../common/base/base.entity';
import { User } from './user.entity';

@Entity('notifications')
@Index('idx_user_read', ['userId', 'isRead'])
export class Notification extends BaseEntity {
  @Column({
    type: 'bigint',
    comment: '用户ID',
  })
  userId: string;

  @Column({
    type: 'enum',
    enum: ['order', 'payment', 'membership', 'system'],
    comment: '通知类型',
  })
  type: 'order' | 'payment' | 'membership' | 'system';

  @Column({
    type: 'varchar',
    length: 200,
    comment: '通知标题',
  })
  title: string;

  @Column({
    type: 'text',
    comment: '通知内容',
  })
  content: string;

  @Column({
    type: 'boolean',
    default: false,
    comment: '是否已读',
  })
  isRead: boolean;

  @Column({
    type: 'timestamp',
    nullable: true,
    comment: '阅读时间',
  })
  readAt?: Date;

  // 关联
  @ManyToOne(() => User)
  @JoinColumn({ name: 'userId' })
  user: User;
}
